﻿using MemoDb.Tests.Model;
using NUnit.Framework;

namespace MemoDb.Tests
{
    [TestFixture]
    public class DeleteTests
    {
       
        [Test]
        public void DeleteWithoutFlush()
        {
            var memo = new Memo()
                .Map<City>();

            var buenosAires = new City
            {
                Id = 1,
                Name = "Buenos Aires"
            };
            using (var s = memo.CreateSession())
            {
                s.Insert(buenosAires);
                s.Flush();
            }

            using (var s = memo.CreateSession())
            {
                var temp = s.GetById<City>(buenosAires.Id);
                s.Delete(temp); //Not flushed!
            }

            using (var s = memo.CreateSession())
            {
                var temp = s.GetById<City>(buenosAires.Id);
                Assert.IsNotNull(temp);
            }
        }

        [Test]
        public void Delete()
        {
            var memo = new Memo()
                .Map<City>();

            var buenosAires = new City
            {
                Id = 1,
                Name = "Buenos Aires"
            };
            using (var s = memo.CreateSession())
            {
                s.Insert(buenosAires);
                s.Flush();
            }

            using (var s = memo.CreateSession())
            {
                var temp = s.GetById<City>(buenosAires.Id);
                s.Delete(temp);
                s.Flush();
            }

            using (var s = memo.CreateSession())
            {
                var temp = s.GetById<City>(buenosAires.Id);
                Assert.IsNull(temp);
            }
        }
    }
}
